#-*- coding:utf-8 -*-
import xlrd
import sys
reload(sys)
sys.setdefaultencoding('utf8')
class read_iplist():
    def __init__(self,paths,root):
        self.paths=paths
        self.root=root
        self._read_file()
    def _read_file(self):
        self.ip=[]
        self.port=[]
        self.uname=[]
        self.passwd=[]
        self.nmonpath=[]
        self.command=[]
        #打开iplist稳定
        excelfile=xlrd.open_workbook(self.paths)
        sheet=excelfile.sheet_by_index(0)
        #获取第一个sheet页，并判断如果小于两行，提示文档为空
        if sheet.nrows<2:
            self.root.set_res('iplist.xlsx为空！'+'\n')
            sys.exit()
        self.rows=sheet.nrows-1
        #遍历文档内容
        for i in range(1,sheet.nrows):
            # if type(sheet.cell_value(i,0))!=unicode or type(sheet.cell_value(i,2))!=unicode or type(sheet.cell_value(i,3))!=unicode\
            # or type(sheet.cell_value(i,4))!=unicode or type(sheet.cell_value(i,5))!=unicode:
            #     self.root.set_res('请设置iplist.xlsx文档中ip、username、password等单元格为文本格式！')
            #     sys.exit()
            self.ip.append(sheet.cell_value(i,0))
            a=sheet.cell_value(i,1)
            if 'int' in str(type(a)) or 'float' in str(type(a)):
                self.port.append(str(int(a)))
            else:self.port.append(a)
            self.uname.append(sheet.cell_value(i,2))
            b=sheet.cell_value(i,3)
            if 'int' in str(type(b)) or 'float' in str(type(b)):
                self.passwd.append(str(int(b)))
            else:self.passwd.append(b)
            self.nmonpath.append(sheet.cell_value(i,4))
            self.command.append(sheet.cell_value(i,5))